package com.chris.libs.example.pages.ext.http2;

import android.view.View;

import com.chris.dev.base.libs.v1.http.params.IdParam;
import com.chris.libs.base.x.mvpp.mvpp.DefaultPresenter;
import com.chris.libs.example.api.UserApi;
import com.chris.libs.example.common.http.DefaultHttp;

import javax.inject.Inject;

/**
 * @author Chris Chan
 * Create on： 2025-02-04 14:25
 * Use for: http2 业务逻辑处理
 * Explain:
 */
public class Http2Presenter extends DefaultPresenter<Http2Contract.UIView>
        implements Http2Contract.Presenter {
    // 数据中心
    private Http2ViewModel viewModel;

    // Dagger2注入构造方法
    @Inject
    public Http2Presenter() {
    }

    // 传入数据中心
    public void setViewModel(Http2ViewModel viewModel) {
        this.viewModel = viewModel;
    }

    // 实例方法，一般由ViewProxy主动调用，必须在契约接口中定义
    @Override
    public void requestAndUpdate() {
        this.viewModel.setInfo("请求并更新的数据");
    }

    @Override
    public void getDataList(View ownView) {
        DefaultHttp.post(UserApi.service.getDataList(IdParam.create("天王盖地虎")), ownView, (response, isSuccess, data) -> {
            this.viewModel.setDataList(data);
        });
    }
}
